<?php
//简单工厂
class SimpleFactory{
    public function createProduction(){
        return new Production();
    }
}
class Production{
    public function getPrice($price){
        return $price * 2;
    }
}
class Test{
    public function __construct(){
        $factory = new SimpleFactory();
        $production = $factory->createProduction();
        if( $production instanceof Production){
            echo 'Nice';
        }
    }
}
//抽象工厂模式
class AbstractFactory{
    public function createPromotionPhoneProduct(int $price, int $discount){
        return new PromotionPhoneProduct($price, $discount);
    }

    public function createPhoneProduct(int $price){
        return new PhoneProduct($price);
    }
}

interface Product{
    public function calculatePrice(): int;
}

class PromotionPhoneProduct implements Product{
    private $price;
    private $discount;

    public function __construct(int $price, int $discount){
        $this->price = $price;
        $this->discount = $discount;
    }

    public function calculatePrice(): int
    {
        return $this->price * $this->discount;
    }
}

class PhoneProduct implements Product{
    private $price;
    public function __construct(int $price){
        $this->price = $price;
    }
    public function calculatePrice(): int{
        return $this->price;
    }
}


//静态方法工厂
/**
 * Class StaticFactory
 * @package Factory\SimpleFactory
 */
class StaticFactory
{
    /**
     * @param string $type
     * @return NumericClass|StringClass
     */
    public static function build(string $type)
    {
        switch ($type) {
            case 'string':
                return new StringClass();
                break;
            case 'numeric':
                return new NumericClass();
            default:
                break;
        }
    }
}

/**
 * Interface TypeInterface
 * @package Factory\SimpleFactory
 */
interface TypeInterface
{
    /**
     * @return mixed
     */
    public function getType();
}

/**
 * Class NumericClass
 * @package Factory\SimpleFactory
 */
class NumericClass implements TypeInterface
{
    /**
     * @return mixed|void
     */
    public function getType()
    {
        // TODO: Implement getType() method.
    }
}

/**
 * Class StringClass
 * @package Factory\SimpleFactory
 */
class StringClass implements TypeInterface
{
    /**
     * @return mixed|void
     */
    public function getType()
    {
        // TODO: Implement getType() method.
    }
}